import { http } from "@kit.NetworkKit";

// HTTP结果接口
export interface HttpResult {
  success: boolean;
  error?: HttpError;
  httpResponse?: http.HttpResponse;
}

// 请求链
export class RequestChain {
  constructor(
    public url: string,
    public method: http.RequestMethod,
    public header: any,
    public data: any,
    public orignal: any,
    public requestConfig: http.HttpRequestOptions
  ) {}
}

// 响应链
export class ResponseChain {
  constructor(
    public url: string,
    public method: http.RequestMethod,
    public response: http.HttpResponse
  ) {}
}

// 拦截器接口
export interface HttpInterceptor {
  onRequest(chain: RequestChain): Promise<RequestChain>;
  onResponse(chain: ResponseChain): Promise<ResponseChain>;
}

export class HttpError extends Error {
  constructor(
    public code: number,
    message: string,
    result?: any
  ) {
    super(message);
    this.name = 'HttpError';
  }
}